import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.text.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;

/**
 * A simple debugging panel.
 */
final class DebugPanel extends JPanel {

  private Image background;

  // ----------------------------------------------------------------------
  // Interface
  // ----------------------------------------------------------------------

  /**
   * Color codes <code>msg</code> according to <code>level</code> and
   * prints it to the screen.
   * @arg msg    message to print
   * @arg c      {@link Color} with which which to print <code>msg</code>
   */
  public synchronized void note(Object msg, Color c) {
    DateFormat df = DateFormat.getTimeInstance(DateFormat.LONG);
    String s = "[" + df.format(new Date()) + "] " + 
      msg + System.getProperty("line.separator");
    SimpleAttributeSet attrs = new SimpleAttributeSet();
    StyleConstants.setForeground(attrs, c);
    try {
      text.getStyledDocument().
        insertString(text.getStyledDocument().getLength(), s, attrs);
    } catch (Exception e) {e.printStackTrace();}
  }

  // ----------------------------------------------------------------------
  // Implementation
  // ----------------------------------------------------------------------

  private final JTextPane text;
  private final DefaultStyledDocument doc;

  public DebugPanel() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    text = new JTextPane(doc = new DefaultStyledDocument());
    text.setPreferredSize(new Dimension(500,500));
    text.setEditable(false);
    JScrollPane scr = new JScrollPane(text);
    add(scr);
  }
  
  public void clear() {
    text.setText("");
  }

}